<?php

namespace App\Console\Commands;

use App\Models\City;
use App\Models\Factory;
use Illuminate\Console\Command;

class CreateFactoryCommand extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'created:factory';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
      $citys=  City::where('parent_id','!=',0)->get();
      foreach ($citys as $city){
          for ($type=1;$type<=3;$type++){
              for ($i=0;$i<10;$i++){
                  $factory=  Factory::find(1)->replicate();
                  $factory->town_id=$city->id;
                  $factory->city_id=$city->parent_id;
                  $factory->title=$factory->title.'_'.$city->name;
                  $factory->baidu_lat=$city->lat;
                  $factory->baidu_lng=$city->lng;
                  $factory->type=$type;
                  $factory->save();
                  $this->info($factory->id);
              }

          }

      }


    }
}
